Ext.define('Mayfle.view.mywork.View', {
  extend: 'Ext.ux.desktop.Module',

  requires: [
    'Ext.data.ArrayStore',
    'Ext.util.Format',
    'Ext.grid.Panel',
    'Ext.grid.RowNumberer',
    'Ext.grid.selection.SpreadsheetModel',
    'Ext.data.Store',

    'Mayfle.model.user.User',
    'Mayfle.utils.Format',
    'Ext.toolbar.Paging',
    'Mayfle.view.mywork.Controller',
    'Mayfle.view.mywork.ViewModel'
  ],

  id: 'myWork',
  controller: 'mywork',
  viewModel: {
    type: 'mywork'
  },

  init: function() {
    this.launcher = {
      'text': '我的工作',
      'iconCls': 'accordion-shortcut'
    };
  },

  createWindow: function() {
    var me = this;
    var desktop = this.app.getDesktop();
    var win = desktop.getWindow('myWork');
    if (!win) {

      var store = Ext.create("Ext.data.Store", {
        model: 'Mayfle.model.user.User',
        pageSize: 2
      });

      win = desktop.createWindow({
        id: 'myWork',
        title: '我的工作',
        width: 800,
        height: 500,
        iconCls: 'accordion-shortcut',
        animCollapse: false,
        constrainHeader: true,
        layout: 'fit',
        hideMode: 'offsets',
        layout: 'fit',
        items: [{
          xtype: 'grid',
          store: store,
          selModel: {
            type: 'spreadsheet',
            columnSelect: true,
            checkboxSelect: true,
            pruneRemoved: false,
            cellSelect: false,
            checkboxSelect: true,
            rowNumbererHeaderWidth: 0
          },
          columns: [{
            text: "编号",
            width: 70,
            sortable: true,
            dataIndex: 'id'
          }, {
            text: "商品名称",
            sortable: true,
            flex: 1,
            dataIndex: 'name'
          }, {
            text: "服务机构",
            width: 200,
            sortable: true,
            dataIndex: 'orgName'
          }, {
            text: "价格",
            width: 100,
            sortable: true,
            renderer: Mayfle.utils.Format.Money,
            dataIndex: 'priceOnline'
          }]
        }],
        tbar: [{
          xtype: 'textfield',
          emptyText: '编号/名称',
          id: 'orgName'
        }, {
          text: '查询',
          tooltip: '查询数据',
          iconCls: 'add',
          handler: me.onClickQuery(store)
        }, '-', {
          text: '移除',
          tooltip: '移除一条',
          iconCls: 'remove'
        }],
        bbar: Ext.create('Ext.PagingToolbar', {
          store: store,
          displayInfo: true,
          displayMsg: '显示第{0} - {1}条数据，一共{2}条',
          emptyMsg: "没有数据"
        })
      });
    }
    store.load();
    return win;
  },
  onClickQuery: function(store) {
    //store.load();
  }

});
